﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//请先添加引用
namespace TierApplication
{
    /// <summary>
    /// 类T_Supplier。
    /// </summary>
    [Serializable]
    public partial class T_Supplier
    {
        public T_Supplier()
        { }
        #region Model
        private string _supplierid;
        private string _suppliername;
        private string _contactname;
        private string _contactphone;
        private string _address;
        private string _postalcode;
        private string _email;
        private string _url;
        private string _payerfullname;
        private string _payerbank;
        private string _payebankaccount;
        /// <summary>
        /// 
        /// </summary>
        public string SupplierID
        {
            set { _supplierid = value; }
            get { return _supplierid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string SupplierName
        {
            set { _suppliername = value; }
            get { return _suppliername; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string ContactName
        {
            set { _contactname = value; }
            get { return _contactname; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string ContactPhone
        {
            set { _contactphone = value; }
            get { return _contactphone; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Address
        {
            set { _address = value; }
            get { return _address; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PostalCode
        {
            set { _postalcode = value; }
            get { return _postalcode; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Email
        {
            set { _email = value; }
            get { return _email; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string URL
        {
            set { _url = value; }
            get { return _url; }
        }
        /// <summary>
        /// 收款单位全称
        /// </summary>
        public string PayerFullName
        {
            set { _payerfullname = value; }
            get { return _payerfullname; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PayerBank
        {
            set { _payerbank = value; }
            get { return _payerbank; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PayeBankAccount
        {
            set { _payebankaccount = value; }
            get { return _payebankaccount; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public T_Supplier(string SupplierID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SupplierID,SupplierName,ContactName,ContactPhone,Address,PostalCode,Email,URL,PayerFullName,PayerBank,PayeBankAccount ");
            strSql.Append(" FROM [T_Supplier] ");
            strSql.Append(" where SupplierID=@SupplierID ");
            SqlParameter[] parameters = {
					new SqlParameter("@SupplierID", SqlDbType.VarChar,-1)};
            parameters[0].Value = SupplierID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["SupplierID"] != null)
                {
                    this.SupplierID = ds.Tables[0].Rows[0]["SupplierID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SupplierName"] != null)
                {
                    this.SupplierName = ds.Tables[0].Rows[0]["SupplierName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ContactName"] != null)
                {
                    this.ContactName = ds.Tables[0].Rows[0]["ContactName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ContactPhone"] != null)
                {
                    this.ContactPhone = ds.Tables[0].Rows[0]["ContactPhone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Address"] != null)
                {
                    this.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PostalCode"] != null)
                {
                    this.PostalCode = ds.Tables[0].Rows[0]["PostalCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Email"] != null)
                {
                    this.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["URL"] != null)
                {
                    this.URL = ds.Tables[0].Rows[0]["URL"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayerFullName"] != null)
                {
                    this.PayerFullName = ds.Tables[0].Rows[0]["PayerFullName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayerBank"] != null)
                {
                    this.PayerBank = ds.Tables[0].Rows[0]["PayerBank"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayeBankAccount"] != null)
                {
                    this.PayeBankAccount = ds.Tables[0].Rows[0]["PayeBankAccount"].ToString();
                }
            }
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string SupplierID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [T_Supplier]");
            strSql.Append(" where SupplierID=@SupplierID ");

            SqlParameter[] parameters = {
					new SqlParameter("@SupplierID", SqlDbType.VarChar,-1)};
            parameters[0].Value = SupplierID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [T_Supplier] (");
            strSql.Append("SupplierID,SupplierName,ContactName,ContactPhone,Address,PostalCode,Email,URL,PayerFullName,PayerBank,PayeBankAccount)");
            strSql.Append(" values (");
            strSql.Append("@SupplierID,@SupplierName,@ContactName,@ContactPhone,@Address,@PostalCode,@Email,@URL,@PayerFullName,@PayerBank,@PayeBankAccount)");
            SqlParameter[] parameters = {
					new SqlParameter("@SupplierID", SqlDbType.VarChar,10),
					new SqlParameter("@SupplierName", SqlDbType.VarChar,50),
					new SqlParameter("@ContactName", SqlDbType.VarChar,50),
					new SqlParameter("@ContactPhone", SqlDbType.VarChar,50),
					new SqlParameter("@Address", SqlDbType.VarChar,50),
					new SqlParameter("@PostalCode", SqlDbType.VarChar,6),
					new SqlParameter("@Email", SqlDbType.VarChar,50),
					new SqlParameter("@URL", SqlDbType.VarChar,50),
					new SqlParameter("@PayerFullName", SqlDbType.VarChar,100),
					new SqlParameter("@PayerBank", SqlDbType.VarChar,100),
					new SqlParameter("@PayeBankAccount", SqlDbType.VarChar,20)};
            parameters[0].Value = SupplierID;
            parameters[1].Value = SupplierName;
            parameters[2].Value = ContactName;
            parameters[3].Value = ContactPhone;
            parameters[4].Value = Address;
            parameters[5].Value = PostalCode;
            parameters[6].Value = Email;
            parameters[7].Value = URL;
            parameters[8].Value = PayerFullName;
            parameters[9].Value = PayerBank;
            parameters[10].Value = PayeBankAccount;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [T_Supplier] set ");
            strSql.Append("SupplierName=@SupplierName,");
            strSql.Append("ContactName=@ContactName,");
            strSql.Append("ContactPhone=@ContactPhone,");
            strSql.Append("Address=@Address,");
            strSql.Append("PostalCode=@PostalCode,");
            strSql.Append("Email=@Email,");
            strSql.Append("URL=@URL,");
            strSql.Append("PayerFullName=@PayerFullName,");
            strSql.Append("PayerBank=@PayerBank,");
            strSql.Append("PayeBankAccount=@PayeBankAccount");
            strSql.Append(" where SupplierID=@SupplierID ");
            SqlParameter[] parameters = {
					new SqlParameter("@SupplierName", SqlDbType.VarChar,50),
					new SqlParameter("@ContactName", SqlDbType.VarChar,50),
					new SqlParameter("@ContactPhone", SqlDbType.VarChar,50),
					new SqlParameter("@Address", SqlDbType.VarChar,50),
					new SqlParameter("@PostalCode", SqlDbType.VarChar,6),
					new SqlParameter("@Email", SqlDbType.VarChar,50),
					new SqlParameter("@URL", SqlDbType.VarChar,50),
					new SqlParameter("@PayerFullName", SqlDbType.VarChar,100),
					new SqlParameter("@PayerBank", SqlDbType.VarChar,100),
					new SqlParameter("@PayeBankAccount", SqlDbType.VarChar,20),
					new SqlParameter("@SupplierID", SqlDbType.VarChar,10)};
            parameters[0].Value = SupplierName;
            parameters[1].Value = ContactName;
            parameters[2].Value = ContactPhone;
            parameters[3].Value = Address;
            parameters[4].Value = PostalCode;
            parameters[5].Value = Email;
            parameters[6].Value = URL;
            parameters[7].Value = PayerFullName;
            parameters[8].Value = PayerBank;
            parameters[9].Value = PayeBankAccount;
            parameters[10].Value = SupplierID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string SupplierID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [T_Supplier] ");
            strSql.Append(" where SupplierID=@SupplierID ");
            SqlParameter[] parameters = {
					new SqlParameter("@SupplierID", SqlDbType.VarChar,-1)};
            parameters[0].Value = SupplierID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(string SupplierID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SupplierID,SupplierName,ContactName,ContactPhone,Address,PostalCode,Email,URL,PayerFullName,PayerBank,PayeBankAccount ");
            strSql.Append(" FROM [T_Supplier] ");
            strSql.Append(" where SupplierID=@SupplierID ");
            SqlParameter[] parameters = {
					new SqlParameter("@SupplierID", SqlDbType.VarChar,-1)};
            parameters[0].Value = SupplierID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["SupplierID"] != null)
                {
                    this.SupplierID = ds.Tables[0].Rows[0]["SupplierID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SupplierName"] != null)
                {
                    this.SupplierName = ds.Tables[0].Rows[0]["SupplierName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ContactName"] != null)
                {
                    this.ContactName = ds.Tables[0].Rows[0]["ContactName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ContactPhone"] != null)
                {
                    this.ContactPhone = ds.Tables[0].Rows[0]["ContactPhone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Address"] != null)
                {
                    this.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PostalCode"] != null)
                {
                    this.PostalCode = ds.Tables[0].Rows[0]["PostalCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Email"] != null)
                {
                    this.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["URL"] != null)
                {
                    this.URL = ds.Tables[0].Rows[0]["URL"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayerFullName"] != null)
                {
                    this.PayerFullName = ds.Tables[0].Rows[0]["PayerFullName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayerBank"] != null)
                {
                    this.PayerBank = ds.Tables[0].Rows[0]["PayerBank"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayeBankAccount"] != null)
                {
                    this.PayeBankAccount = ds.Tables[0].Rows[0]["PayeBankAccount"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [T_Supplier] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

